//
//  AttrPriceLabel.m
//  wtshoppingcite
//
//  Created by Baojia-LC on 14-10-20.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "AttrPriceLabel.h"

@implementation AttrPriceLabel

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
//- (void)drawRect:(CGRect)rect {
//    // Drawing code
//
//    if(_type == 1){
//        CGContextRef context    = UIGraphicsGetCurrentContext(); //获取画布
//        CGContextSetStrokeColorWithColor(context, COLOR_RGB(230, 113, 143).CGColor); //线条颜色
//        CGContextSetShouldAntialias(context, NO);//设置线条平滑，不需要两边像素宽
//        CGContextSetLineWidth(context, 1.0f);//设置线条宽度
//        CGContextMoveToPoint(context,  rect.origin.x,9);  //线条起始点
//        CGContextAddLineToPoint(context, rect.size.width, 11);//线条结束点
//        CGContextStrokePath(context);//结束，也就是开始画
//    }
//
//}

-(void)setPriceType:(int)type text:(NSString*)content{
    
    _type = type;
    NSMutableParagraphStyle *ps = [[NSMutableParagraphStyle alloc] init];
    [ps setAlignment:NSTextAlignmentLeft];
    [ps setLineBreakMode:NSLineBreakByTruncatingTail];
    [ps setBaseWritingDirection:NSWritingDirectionLeftToRight];
    NSDictionary *attribs = @{
                              NSFontAttributeName:[UIFont boldSystemFontOfSize:14],
                              NSParagraphStyleAttributeName:ps};
    NSMutableAttributedString * attributedText = [[NSMutableAttributedString alloc] initWithString:content attributes:attribs];
    //        NSString*suffix =  [self substring:@"5" content:content];
    //        NSString*suffix =  content;
    //        NSRange range = [content rangeOfString:suffix];
    
    if(type == 2){
        CGSize size = [content getSizeOfStringFontSize:14 constroSize:CGSizeMake(60, MAXFLOAT)];
        _line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 9, size.width, 1)];
        _line.backgroundColor = COLOR_RGB(185, 185, 185);
        [self addSubview:_line];
        NSRange range = NSMakeRange(0, content.length);
//        [attributedText addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlinePatternSolid | NSUnderlineStyleSingle] range:range];
        [attributedText addAttribute:NSForegroundColorAttributeName value:COLOR_RGB(185, 185, 185) range:range];
        [attributedText addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:14] range:range];
        self.attributedText = attributedText;
    }else{
        
        NSRange range = NSMakeRange(0, 1);
        [attributedText addAttribute:NSForegroundColorAttributeName value:COLOR_RGB(230, 113, 143) range:range];
        [attributedText addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:11] range:range];
        self.attributedText = attributedText;
    }
    //        [self setNeedsDisplay];
}




-(NSString*)substring:(NSString*)subs content:(NSString*)text{
    NSRange range = [text rangeOfString:subs];
    if(range.location != NSNotFound){
        return [text substringToIndex:range.location];
    }
    return @"";
}

-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.backgroundColor = [UIColor clearColor];
    return label;
}

@end


